def get_member_usage_input(member_name):
    """获取指定成员的水电用量输入"""
    while True:
        try:
            electricity = float(input(f"请输入{member_name}的用电量（度）：").strip())
            if electricity < 0:
                print("用电量不能为负数，请重新输入")
                continue
            break
        except ValueError:
            print("请输入有效的数字")
    
    while True:
        try:
            water = float(input(f"请输入{member_name}的用水量（吨）：").strip())
            if water < 0:
                print("用水量不能为负数，请重新输入")
                continue
            break
        except ValueError:
            print("请输入有效的数字")
    
    return {"electricity": electricity, "water": water}

def manage_member_usage_interaction(current_members_data, member_list):
    """管理成员用量的交互函数"""
    while True:
        # 显示当前成员及用量
        print("\n当前已录入的成员用量：")
        if not current_members_data:
            print("暂无数据")
        else:
            for name, usage in current_members_data.items():
                print(f"{name}: 用电 {usage['electricity']} 度，用水 {usage['water']} 吨")
        
        print("\n请选择要操作的成员：")
        for i, name in enumerate(member_list, 1):
            print(f"{i}. {name}")
        
        print(f"{len(member_list) + 1}. 添加新成员")
        print(f"{len(member_list) + 2}. 完成录入")
        
        while True:
            try:
                choice = int(input("请输入选项编号：").strip())
                if 1 <= choice <= len(member_list):
                    selected_member = member_list[choice - 1]
                    print(f"\n正在编辑 {selected_member} 的用量信息")
                    usage_data = get_member_usage_input(selected_member)
                    current_members_data[selected_member] = usage_data
                    print(f"{selected_member} 的用量信息已更新")
                    break
                elif choice == len(member_list) + 1:
                    new_member = input("请输入新成员姓名：").strip()
                    if new_member:
                        if new_member in member_list:
                            print("该成员已存在")
                        else:
                            member_list.append(new_member)
                            usage_data = get_member_usage_input(new_member)
                            current_members_data[new_member] = usage_data
                            print(f"已添加新成员 {new_member}")
                    else:
                        print("成员姓名不能为空")
                    break
                elif choice == len(member_list) + 2:
                    return current_members_data, member_list
                else:
                    print("无效的选项，请重新输入")
            except ValueError:
                print("请输入有效的数字选项")    